package com.example.demo;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FilenameFilter;
import java.util.*;

public class FileTset {
    static List<String> lists=new ArrayList<>();
    static List<String> newList=new ArrayList<>();

    static int num=0;

    public static void main(String[] args) {

        String path = "C:\\Users\\tuiche\\Desktop\\Kay\\Kaybean Lau";		//要遍历的路径
        File fi = new File(path);		//获取其file对象
        List<String> paths=new ArrayList<String>();
        func(fi,paths);
        for (String pa:paths) {
            func(new File(pa));
        }
        System.out.println(num);
        for (int i = 0; i < lists.size(); i++) {
            //   /root/jdk/test/111/test88/Kaybean Lau 转换成/resource/zhhhh/Archive/index.html
//            System.out.println(lists.get(i));
            String imgUrl=lists.get(i).split("/root/jdk/test")[1];
            newList.add(imgUrl);
        }
        for (int i = 0; i < newList.size(); i++) {
            System.out.println(newList.get(i));
        }
    }

    private static void func(File file,List<String> paths){
        File[] fs = file.listFiles();
        if (fs != null) {
            for(File f:fs){
                if(f.isDirectory()){
                    paths.add(f.getPath());
                    num++;
                }
            }
        }
    }
    private static void func(File file){
        File[] fs = file.listFiles();
        if (fs != null) {
            for(File f:fs){
                if(f.isFile()&&!(f.getName().contains(".DS_Store"))&&f.getName().contains(".jpg")){
                    num++;
                    System.out.println(f.getPath());
                    lists.add(f.getPath());
                }
            }
        }
    }
}
